package com.xujie.property_warranty_system.common;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * 密码加密测试类
 */
public class test {
    
    public static void main(String[] args) {
        // 创建密码编码器实例
        PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
        
        // 测试123456的加密
        String password = "123456";
        String encrypted = passwordEncoder.encode(password);
        
        System.out.println("明文密码: " + password);
        System.out.println("加密结果: " + encrypted);
        
        // 验证加密是否正确
        boolean isValid = passwordEncoder.matches(password, encrypted);
        System.out.println("验证结果: " + isValid);
        
        // 验证数据库中现有的密码是否正确
        String dbPassword = "$2a$10$N.zmdr9k7uOCQb376NoUnuTJ8iAt6Z5EHsM8lE9lBOsl7iKTVEFDi";
        boolean dbValid = passwordEncoder.matches(password, dbPassword);
        System.out.println("数据库密码验证: " + dbValid);
    }
}
